/**
 * com.cnhis.his.customer.service.SysrolePermissionsService.java
 */
package com.mbmed.doctor.medadvice.service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Request;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.mbmed.doctor.commons.mapper.ModelVo;
import com.mbmed.doctor.medadvice.bo.SysrolePermissionsBo;
import com.mbmed.doctor.medadvice.mapper.SysrolePermissions;

/**
 * @file  SysrolePermissionsService.java
 * @author 刘武
 * @version 0.1
 * @todo	SysrolePermissions服务操作接口
 * Copyright(C), 2013-2014
 *		 Shenzhen Coordinates Software Development Co., Ltd.
 * History
 *   	1. Date: 2014-12-24 10:10:36
 *      	Author: 刘武
 *      	Modification: this file was created
 *   	2. ...
 */
@Path("/sysrolePermissions")
@Component
public class SysrolePermissionsService {
	
	private static Logger logger = Logger.getLogger(SysrolePermissions.class);
	
	@Autowired
	private SysrolePermissionsBo sysrolePermissionsBo;
	
	@Context
	Request request;

	
	/**
	 * 查找所有数据库记录
     * @return type : List 返回查询操作所有符合条件的记录的VO对象集合，操作失败返回null
     */
	@GET
	@Produces({MediaType.APPLICATION_XML,MediaType.APPLICATION_JSON})
    public List<SysrolePermissions> getAll() throws Exception{
        List<SysrolePermissions> list = new ArrayList<SysrolePermissions>();
        return sysrolePermissionsBo.getAll();        
    }
	
    /**
     * 查找符合条件的所有数据库记录
     * @param id 与数据库中主键对应的值
     * @return type :  返回查询操作所有符合条件的记录的VO对象，操作失败返回null
     * @throws Exception
     */
	@GET
	@Path("{id}")
	@Produces({MediaType.APPLICATION_XML,MediaType.APPLICATION_JSON})
    public SysrolePermissions getSysrolePermissions(@PathParam("id") String id) throws Exception{
    	SysrolePermissions sysrolePermissions = null;
    	return sysrolePermissionsBo.get(id);        
    }
   
	 /**
     * 查找符合条件的所有数据库记录
     * @param id 与数据库中主键对应的值
     * @return type :  返回查询操作所有符合条件的记录的VO对象，操作失败返回null
     * @throws Exception
     */
	@GET
	@Path("/getconfirmadvice")
	@Produces({MediaType.APPLICATION_JSON})
    public ModelVo getConfirmAdvice(@QueryParam("id") String id) throws Exception{
		
		ModelVo modelVo = new ModelVo();
		List<SysrolePermissions> list = new ArrayList<SysrolePermissions>();
		Map<String,Object> map = new HashMap<String,Object>();
		map.put("id", id);
		list = sysrolePermissionsBo.getConfirmAdvice(map);
		Iterator<SysrolePermissions> it = list.iterator();
		while(it.hasNext()){
			SysrolePermissions sysrolePermissions = it.next();
			if("1".equals(sysrolePermissions.getPermission()+"")){
				modelVo.setResult("false");
				return modelVo;
			}
		}
		modelVo.setResult("success");
    	return modelVo;        
    }
}
